import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import holidays

# 加载数据集并进行数据预处理
df = pd.read_csv('order_train1_new.csv')
df['order_date'] = pd.to_datetime(df['order_date'])
df['is_holiday'] = df['order_date'].isin(holidays.China(years=[2015, 2016, 2017, 2018]))
df['is_holiday'] = df['is_holiday'].astype(int)

# 将数据集分成两部分：节假日数据和非节假日数据
holiday_df = df[df['is_holiday'] == 1]
non_holiday_df = df[df['is_holiday'] == 0]

# 计算每天的平均需求量
holiday_demand = holiday_df.groupby(['order_date'])['ord_qty'].mean()
non_holiday_demand = non_holiday_df.groupby(['order_date'])['ord_qty'].mean()

# 可视化比较节假日和非节假日的平均需求量
plt.figure(figsize=(10, 6))
plt.plot(holiday_demand.index, holiday_demand.values, label='Holiday')
plt.plot(non_holiday_demand.index, non_holiday_demand.values, label='Non-Holiday')
plt.title('Average demand on holiday vs non-holiday')
plt.xlabel('Date')
plt.ylabel('Average demand')
plt.legend()
plt.show()
